﻿using DotNetty.Buffers;
using QQ.Client;
using QQ.Codecs;
using static QQ.Codecs.DotNettyByteBufferExtensions.LengthType;

namespace QQ.Packet.Request.TLV
{
    public class TLV0x128 : IRequest
    {
        private readonly QQDeviceConfig config;
        private byte isGuidFromFileNull { get; set; } = 0;
        private byte isGuidAvailable { get; set; } = 1;
        private byte isGuidChanged { get; set; } = 0;
        private IByteBuffer guidFlag { get; set; } = "11 00 00 00".HexStringToByteBuffer();
        public TLV0x128(QQDeviceConfig config)
        {
            this.config = config;
        }
        public IByteBuffer Serialize() => Unpooled.Buffer()
            .WriteShort(0)
            .WriteByte(isGuidFromFileNull)
            .WriteByte(isGuidAvailable)
            .WriteByte(isGuidChanged)
            .WriteBytes(guidFlag)
            .WriteBytesWithLength(config.model.ToByteBuffer(), SHORT, limitLength: 32)
            .WriteBytesWithLength(config.GUID, SHORT, 16)
            .WriteBytesWithLength(config.brand.ToByteBuffer(), SHORT, limitLength: 16);
    }
}